/**
 * 
 */
package leetCode;

import java.util.ArrayList;

/**
 * @author zhongfang
 *
 */
public class MinimumIndexSumofTwoLists {
    public static String[] findRestaurant(String[] list1, String[] list2) {
        ArrayList<String> reStrings=new ArrayList<>();
        int minSum=2000;
        for (int i = 0; i < list1.length; i++) {
        	if(i>minSum){
        		break;
        	}
			for (int j = 0; j < list2.length; j++) {
				if(i+j>minSum){
					break;
				}
				if(list1[i].equals(list2[j])){
					int sum=i+j;
					if(sum<minSum){
						minSum=sum;
						reStrings=new ArrayList<>();
						reStrings.add(list1[i]);
					}else if (sum==minSum) {
						reStrings.add(list1[i]);
					}
				}
			}
		}
        String[] result=new String[reStrings.size()];
        for (int i = 0; i < result.length; i++) {
			result[i]=reStrings.get(i);
		}
        return result;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String[] string1={"Shogun", "Tapioca Express", "Burger King", "KFC"};
		String[] string2={"Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"};
		String[] result=findRestaurant(string1, string2);
		for (String string : result) {
			System.out.println(string);
		}
	}

}
